import 'package:gold/generated/json/base/json_convert_content.dart';
import 'package:gold/model/address_model.dart';

AddressModel $AddressModelFromJson(Map<String, dynamic> json) {
  final AddressModel addressModel = AddressModel();
  final int? id = jsonConvert.convert<int>(json['id']);
  if (id != null) {
    addressModel.id = id;
  }
  final int? userId = jsonConvert.convert<int>(json['user_id']);
  if (userId != null) {
    addressModel.userId = userId;
  }
  final String? sex = jsonConvert.convert<String>(json['sex']);
  if (sex != null) {
    addressModel.sex = sex;
  }
  final String? name = jsonConvert.convert<String>(json['name']);
  if (name != null) {
    addressModel.name = name;
  }
  final String? phone = jsonConvert.convert<String>(json['phone']);
  if (phone != null) {
    addressModel.phone = phone;
  }
  final String? address = jsonConvert.convert<String>(json['address']);
  if (address != null) {
    addressModel.address = address;
  }
  final String? houseNumber = jsonConvert.convert<String>(json['house_number']);
  if (houseNumber != null) {
    addressModel.houseNumber = houseNumber;
  }
  final int? isDefault = jsonConvert.convert<int>(json['is_default']);
  if (isDefault != null) {
    addressModel.isDefault = isDefault;
  }
  final String? createdAt = jsonConvert.convert<String>(json['created_at']);
  if (createdAt != null) {
    addressModel.createdAt = createdAt;
  }
  final String? updatedAt = jsonConvert.convert<String>(json['updated_at']);
  if (updatedAt != null) {
    addressModel.updatedAt = updatedAt;
  }
  return addressModel;
}

Map<String, dynamic> $AddressModelToJson(AddressModel entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['id'] = entity.id;
  data['user_id'] = entity.userId;
  data['sex'] = entity.sex;
  data['name'] = entity.name;
  data['phone'] = entity.phone;
  data['address'] = entity.address;
  data['house_number'] = entity.houseNumber;
  data['is_default'] = entity.isDefault;
  data['created_at'] = entity.createdAt;
  data['updated_at'] = entity.updatedAt;
  return data;
}

extension AddressModelExtension on AddressModel {
  AddressModel copyWith({
    int? id,
    int? userId,
    String? sex,
    String? name,
    String? phone,
    String? address,
    String? houseNumber,
    int? isDefault,
    String? createdAt,
    String? updatedAt,
  }) {
    return AddressModel()
      ..id = id ?? this.id
      ..userId = userId ?? this.userId
      ..sex = sex ?? this.sex
      ..name = name ?? this.name
      ..phone = phone ?? this.phone
      ..address = address ?? this.address
      ..houseNumber = houseNumber ?? this.houseNumber
      ..isDefault = isDefault ?? this.isDefault
      ..createdAt = createdAt ?? this.createdAt
      ..updatedAt = updatedAt ?? this.updatedAt;
  }
}